package com.situ.web.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.situ.web.entity.Banji;
import com.situ.web.entity.Course;
import com.situ.web.service.IBanjiService;
import com.situ.web.service.impl.BanjiServiceImpl;

@WebServlet("/banji")
public class BanjiServlet extends HttpServlet{
	private IBanjiService banjiService = new BanjiServiceImpl();

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("BanjiServlet.service()");
		
		String method = req.getParameter("method");
		// 如果这个method=null或者是""字符串，就让这么method的值为selectAll
		if (method == null || "".equals(method)) {
			method = "selectAll";
		}
		switch (method) {
		case "selectAll":
			selectAll(req, resp);
			break;
		case "insert":
			insert(req, resp);
			break;
		default:
			break;
		}
		
		
	}

	private void insert(HttpServletRequest req, HttpServletResponse resp) {
		req.getParameter("name");
	}

	private void selectAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		List<Banji> list = banjiService.selectAll();
		
		// 把list集合放到req这个内存区域里面
		req.setAttribute("list", list);
		// 转发（跳转）到course_list.jsp页面进行展示
		req.getRequestDispatcher("banji_list.jsp").forward(req, resp);
	}
}
